<?php
namespace app\appclass\model;
use app\BaseModel;
use think\facade\Db;



class CardLog extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_appclass_card_user_log';


    /**
     * @author chenniang
     * @DataTime: 2021-05-11 16:00
     * @功能说明:添加
     */
    public function dataAdd($uniacid,$card_id,$status,$controller,$cancel_price=0,$cancel_type=0,$open_time=0){

        $data['create_time'] = !empty($open_time)?$open_time:time();

        $data['uniacid']     = $uniacid;

        $data['card_user_id']= $card_id;

        $data['status']      = $status;

        $data['controller']  = $controller;

        $data['cancel_price']  = $cancel_price;

        $data['cancel_type']  = $cancel_type;

        $res = $this->insert($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-11 16:03
     * @功能说明:编辑
     */
    public function dataUpdate($dis,$data){

        $res = $this->where($dis)->update($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-11 16:04
     * @功能说明:详情
     */
    public function dataInfo($dis){

        $data = $this->where($dis)->find();

        return !empty($data)?$data->toArray():[];

    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-11 16:05
     * @功能说明:
     */
    public function dataList($dis,$page=10){

        $data = $this->where($dis)->order('create_time desc,id desc')->paginate($page)->toArray();

        if(!empty($data['data'])){

            $card_model = new CardUser();

            foreach ($data['data'] as &$v){

                $card = $card_model->dataInfo(['id'=>$v['card_user_id']]);
                //会员卡名字
                $v['card_name'] = $card['card_name'];
                //教师名字
                $v['adviser_name'] = lbUserName($card['adviser']);

                $v['create_time']  = date('Y-m-d H:i:s',$v['create_time']);

                $v['pay_price']    = round($card['pay_price'],2);

                $v['controller_name'] = !empty($v['controller'])?lbUserName($v['controller']):'后台操作';
            }

        }

        return $data;

    }


















}